package test0109.test05;

import java.util.ArrayList;
import java.util.List;

public class CC {
    String name;
    ArrayList<EE> e = new ArrayList<>();
    public CC() {
    }

    public CC(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "CC{" +
                "name='" + name + '\'' +
                '}';
    }

    public void add(EE ee) {
        e.add(ee);
    }
    public void add(String name ,int age ,int money) {
        EE newe = new EE(name , age , money);
        e.add(newe);
    }

    public void printAll() {
        for (int i = 0; i < e.size(); i++) {
            System.out.println(e.get(i));
        }
    }

    public EE m1() {
        EE finallied = e.get(0);
        for (int i = 1; i < e.size(); i++) {
            if(e.get(i).age > finallied.age) {
                finallied = e.get(i);
            }
        }
        return finallied;
    }

    public EE m2() {
        EE finallied = e.get(0);
        for (int i = 1; i < e.size(); i++) {
            if(e.get(i).money < finallied.money) {
                finallied = e.get(i);
            }
        }
        return finallied;
    }

    public EE m3(String findname) {
        EE finallied = null;
        for (int i = 0; i < e.size(); i++) {
            if(e.get(i).name.equals(findname)) {
                finallied = e.get(i);
            }
        }
        return finallied;
    }

    public double m4() {
        double sum = 0;
        for (int i = 0; i < e.size(); i++) {
            sum += e.get(i).money;
        }
        return sum/(e.size());
    }

    public List m5() {
        List finallied = new ArrayList();
        for (int i = 0; i < e.size(); i++) {
            if(e.get(i).money > m4()) {
                finallied.add(e.get(i));
            }
        }
        return finallied;

    }
}
